refactor: rename stringMethodR/C to methodR/C and add collection methods (#524 Phase1)#526
Merged
Merged
Conversation
Rename smalrubyRuby_stringMethodR → smalrubyRuby_methodR and smalrubyRuby_stringMethodC → smalrubyRuby_methodC to support methods on all receiver types (string, array, hash). New REPORTER methods: lines, max, sort, join, keys, values New COMMAND methods: sort!, reverse! Add automatic migration for old project files (stringMethodR/C opcodes are replaced with methodR/C on load, unconditionally). Refs #524 (Phase 1 #4-#9) Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
|
🚀 Preview deployed: https://smalruby.jp/smalruby3-editor/feat/tryruby-method-r-refactor/ |
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
- Convert list variable receivers to data_listcontents so the VM
receives actual list contents (not empty scalar variable value)
- Hash#keys/values reference the correct sub-list (__hash_X_keys__
/ __hash_X_values__)
- VM methodR: implement actual array operations (max finds maximum,
sort sorts numerically, join concatenates with separator, lines
splits by newline)
Verified all 10 methods produce correct runtime output:
reverse→"ymmiJ", delete→"heo", gsub→"herro",
max→"47", sort→"12 35 47", join(", ")→"12, 47, 35",
keys→"Ruby", values→"good", lines→"hello\n world\n"
Refs #524
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
github-actions Bot
pushed a commit
that referenced
this pull request
Apr 18, 2026
…method-r-refactor refactor: rename stringMethodR/C to methodR/C and add collection methods (#524 Phase1)
9 tasks
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
smalrubyRuby_stringMethodR→smalrubyRuby_methodRにリネーム(文字列以外のレシーバーにも対応)smalrubyRuby_stringMethodC→smalrubyRuby_methodCにリネームlines,max,sort,join,keys,valuessort!,reverse!Changes
VM (scratch-vm)
src/extensions/smalruby_ruby/index.js— opcode リネーム + 新メソッドのargumentsByMethod・メニュー・実行ロジック追加src/extensions/smalruby_ruby/translations.json— 翻訳キーをmethodR/methodCに更新src/serialization/smalruby-migration.js—migrateStringMethodBlocks()追加src/virtual-machine.js—loadProjectで常にマイグレーション実行GUI (scratch-gui)
src/lib/ruby-to-blocks-converter/smalruby-ruby.js— opcode リネーム + 新メソッドのコンバーター登録src/lib/ruby-generator/smalruby-ruby.js— opcode リネーム + COMMAND の引数なし対応Tests
sort!テスト追加migrateStringMethodBlocksテスト追加TryRuby 対応状況
この PR で以下のレッスンが新たにブロック変換可能になる見込み:
[12,47,35].max→.maxticket.sort!→.sort!poem.lines→.linespoem.lines.reverse→.lines+.reverseチェーンpoem.lines.reverse.join→.lines+.reverse+.joinチェーンbooks.keys→.keysRelated Issues
Refs #524 (Phase 1 #4-#9)